GameState.over = function(game) {};
GameState.over.prototype = {
  create: function() {
    var that = this;
    this.goShare();
    $.ajax({
      url : 'http://app.zhongledp.tv/fruittv/games/addFruitCount',
      data: 'z=' + JSON.stringify({userId: '9567d761-505b-4340-920c-45d199f0cdc4', fruitCount: 10, id: crossToken}),
      dataType: 'json',
      type: 'get',
      success: function(res) {
        console.log(res);
        that.goShare();
        if (res.result === 'ok') {
          //todo 区别显示？
          
        } else {
          crossToken = '';
        }
      }
    });



  },

  goShare: function() {
    var bgUp = game.add.sprite(0, 0, 'bgUp');
    game.add.sprite(0, bgUp.height - 28, 'bgDown');
    game.add.sprite(10, 100, 'share');

    var btn = game.add.sprite(50, 460, 'shareBtn');
    var againBtn = game.add.sprite(310, 460, 'again');

    againBtn.inputEnabled = true;
    againBtn.input.pixelPerfectClick = true;
    againBtn.events.onInputDown.add(this.goStart, this);

    btn.inputEnabled = true;
    btn.input.pixelPerfectClick = true;
    btn.events.onInputDown.add(this.doShare, this);
    var text1 = game.add.text(210, 230, Math.floor(totalTime/10), { font: "48px Arial", fill: "#ffffff", align: "center" });
    var text2 = game.add.text(330, 280, score, { font: "48px Arial", fill: "#ffffff", align: "center" });
    var text3 = game.add.text(310, 340, this.makeFruit(), { font: "48px Arial", fill: "#ffffff", align: "center" });
  },


  goStart: function() {
    game.state.start('begin');
  },

  doShare: function() {
    if (!localUser.params.userId){
      alert('need user');
      return false;
    }
    var argString = '{"title":"我在'+Math.floor(totalTime/10)+'秒内将水蜜桃妹纸砸了'+score+'次';
    argString += '得果豆'+this.makeFruit()+'，换礼品去！好残忍有木有？';
    argString += ', "shareContent": "水果TV，边看边玩！开启娱乐互动新模式 ! 体验全民娱乐新潮流！", "shareUrl": "'+window.location.host+ window.location.path+'"}';
    if (localUser.isNative) {
      if ( JSBridge ) {
          JSBridge.invoke('share',{callback:'appShare',args: argString});
        }
    } else {
      $('#mcover').css('display', '');
    }
  },

  makeFruit: function() {
    var fruit = 9;
    if (score < 30) {
      fruit = 2;
    } else if (score < 60) {
      fruit = 4;
    } else {
      fruit = 6
    }
    fruit = fruit > totalFruit ? totalFruit : fruit;
    return fruit;
  }
};